﻿using NUnit.Framework;
using System.Linq;
using AdventureWorks.Domain;
using System.Collections.Generic;
using AdventureWorks.DataAccess.Specifications;
using AdventureWorks.DataAccess.Repositories;
using AdventureWorks.DataAccess.Utils;
using NHibernate.Linq;
namespace AdventureWorks.DataAccess.Test.Specifications
{
    [TestFixture]
    public class ProductSpecificationTest
    {
        private IQueryable<Product> query;
        private ProductSpecification specification;

        [SetUp]
        public void Setup()
        {
            var d = new List<Product>() {
                new Product { Name = "ABC", Color = "White", SubCategory = new ProductSubCategory { Category = ProductCategory.Bikes, Name = "Sub1"}, ProductNumber = "A-KLM"},
                new Product { Name = "DEF", Color = "Red", SubCategory = new ProductSubCategory { Category = ProductCategory.Clothing, Name = "Sub2"}, ProductNumber = "B-SOR"}
            };
            query = d.AsQueryable();
        }

        [Test]
        public void SpecificationTest()
        {
            specification = new ProductSpecification() { ProductNumber = "B-SOR" };
            var x = specification.IsSatisfiedBy(query);
            var y = x.ToList();
            Assert.AreEqual(1, y.Count);
        }

        [Test]
        public void xx()
        {
            /*var a = new NHibernateRepository<Product>(SessionManager.SessionFactory.OpenSession());
            var x = a.Find(new ProductSpecification());
            var i = x.ToList();
            var y = "";*/
            var j = SessionManager.SessionFactory.OpenSession();
            var u =j.BeginTransaction();
            var n = j.Query<Product>().Select(x => x).ToList();
            var y = "";
            u.Commit();

        }
    }

}
